package com.traveldream.entities;

import java.io.Serializable;
import javax.persistence.*;
import java.util.Date;
import java.util.List;


/**
 * The persistent class for the booking database table.
 * 
 */
@Entity
@NamedQueries({
	@NamedQuery(name="Booking.findAll", query="SELECT b FROM Booking b"),
	@NamedQuery(name="Booking.findByCustomer",query="SELECT b FROM Booking b WHERE b.user.email LIKE :customerEmail")
})
public class Booking implements Serializable {
	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private BookingPK id;

	@Temporal(TemporalType.DATE)
	private Date date;

	//bi-directional many-to-one association to Packet
	@ManyToOne
	private Packet packet;

	//bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name="customer_email")
	private User user;

	//bi-directional many-to-one association to Invite
	@OneToMany(mappedBy="booking")
	private List<Invite> invites;

	public Booking() {
	}

	public BookingPK getId() {
		return this.id;
	}

	public void setId(BookingPK id) {
		this.id = id;
	}

	public Date getDate() {
		return this.date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Packet getPacket() {
		return this.packet;
	}

	public void setPacket(Packet packet) {
		this.packet = packet;
	}

	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public List<Invite> getInvites() {
		return this.invites;
	}

	public void setInvites(List<Invite> invites) {
		this.invites = invites;
	}

	public Invite addInvite(Invite invite) {
		getInvites().add(invite);
		invite.setBooking(this);

		return invite;
	}

	public Invite removeInvite(Invite invite) {
		getInvites().remove(invite);
		invite.setBooking(null);

		return invite;
	}
	
	@Override 
	public boolean equals(Object o) {
		Booking b=(Booking)o;
		return b.user.getEmail().equals(this.user.getEmail()) && this.packet.getId()==b.packet.getId();
	}

}